// templates/deliver/pages/finishOrderAll/finishOrderAll.js
const app = getApp();
import Notify from '@vant/weapp/notify/notify';
import Toast from '@vant/weapp/toast/toast';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        // 文章数组
        articleList: [],
        id: 0, //司机id
        name: '', //司机名字
        //每页显示的行数：
        pagesize: 35,
        page: 1, //页码
        state: 1,
        sumpage: 0, //总共多少页
        //用于数组的追加和暂存
        allProject: [],

        view_delivery_man_id: 0,
        view_driver_name: '',
        view_delivery_district_id: 0

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {

        let view_delivery_man_id = wx.getStorageSync('view_delivery_man_id') || 0
        let view_driver_name = ''
        let view_delivery_district_id = 0
        if (view_delivery_man_id > 0) {
            view_driver_name = wx.getStorageSync('view_driver_name')
            view_delivery_district_id = wx.getStorageSync('view_delivery_district_id')
        }

        this.setData({
            id: options.city_id,
            name: options.city_name,
            view_delivery_man_id,
            view_driver_name,
            view_delivery_district_id
        })
        this.queryOrderAll()
    },
    /**
     * 获取完成订单信息
     */
    queryOrderAll() {
        var self = this;
        let url = app.globalData.URL
        let mall_id = app.globalData.mall_id
        let id = this.data.id
        let name = this.data.name
        let pagesize = this.data.pagesize
        let page = this.data.page

        wx.request({
            url: url + '/deliver.OrderV2/queryOrderAll',
            method: 'POST',
            data: {
                mall_id,
                id,
                name,
                pagesize,
                page
            },
            success(result) {
                let resData = result.data.data;
             
                let page = self.data.page //获取第几页
                let sumpage = result.data.join //获取总分页页数 
               
                if (page ===  Number(sumpage)) {
                    Notify({ type: 'success', message: '加载完了' });
                } else {
                    //循环将结果集追加到数组后面
                    for (var i = 0; i < result.data.data.length; i++) {
                        self.data.allProject.push(resData[i]);
                    }
                    self.setData({
                        articleList: self.data.allProject,
                        sumpage
                    });
                }
                wx.hideLoading();
            }

        });
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {
        console.log(1)
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom(e) {

        var self = this;
        var sumpage = self.data.sumpage;
        var page = self.data.page;
        if (page !== Number(sumpage)) {
            wx.showLoading({
                title: '加载中...',
            },2000);
            self.data.page = self.data.page + 1;
            self.queryOrderAll()
        } else {
            Toast.fail('到底了~~');
        }

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})